# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: db\tables\users.py
__author__ = "sanyi"
from sqlalchemy import *
from sqlalchemy.orm import mapper
from sqlalchemy.dialects.postgresql import UUID as TYPE_UUID
from sqlalchemy.dialects.postgresql import ENUM as TYPE_ENUM
from sqlalchemy.dialects.postgresql import JSONB as TYPE_JSONB
from db.tables import metadata

UserRoles = TYPE_ENUM(
    "none",
    "master",
    "tech_admin",
    "tester",
    "auditor",
    name="user_roles",
    metadata=metadata,
)
LicenseTypes = TYPE_ENUM(
    "trial", "customer", "demo", name="license_types", metadata=metadata
)


class UserConfirmation:
    NEEDS_VALIDATION = "needs validation"
    NEEDS_ADMIN_VALIDATION = "needs admin validation"
    REJECTED = "rejected"
    AUTO_VALIDATION_FAILED = "auto validation failed"
    AUTO_VALIDATED = "auto validated"
    ADMIN_VALIDATED = "admin validated"


UsersTable = Table(
    "users",
    metadata,
    Column("user_id", TYPE_UUID, primary_key=True),
    Column("email", TEXT, nullable=False),
    Column("password", TEXT),
    Column("confirmation", TEXT),
    Column("first_name", TEXT),
    Column("last_name", TEXT),
    Column("phone", TEXT),
    Column("country", TEXT),
    Column("website", TEXT),
    Column("company", TEXT),
    Column("owner_id", TYPE_UUID, ForeignKey("users.user_id", ondelete="CASCADE")),
    Column(
        "license_key", TEXT, ForeignKey("licenses.license_key", ondelete="RESTRICT")
    ),
    Column("api_key", TEXT, unique=True),
    Column("api_key_enabled", Boolean, default=False),
    Column("access_all_groups", Boolean, default=False),
    Column("role", UserRoles, default="none"),
    Column("notifications", TYPE_JSONB, default=dict()),
    Column("enabled", Boolean, default=True),
    Column("created", DateTime(true), default="now()"),
    Column("modified", DateTime(true), default="now()"),
    Column("deleted_at", DateTime(true)),
    Column("license_type", LicenseTypes),
    Column("extra", TYPE_JSONB, default=dict()),
    Column("otp", TEXT),
    Column("otp_required", BOOLEAN, default=False),
    Column("pwd_expires", DateTime(true)),
    Column("pwd_max_age", INTEGER, default=0),
    Column("pwd_history", INTEGER, default=0),
    Column("max_session", INTEGER, default=0),
    Column("lockout", TYPE_JSONB),
)
Index(
    "ix_users_not_deleted",
    UsersTable.c.deleted_at,
    postgresql_where=UsersTable.c.deleted_at.is_(None),
)
Index(
    "ix_users_unique_active_email",
    UsersTable.c.email,
    unique=True,
    postgresql_where=UsersTable.c.deleted_at.is_(None),
)


class UserRow(object):
    user_id = None
    owner_id = None
    email = None
    password = None
    license_key = None
    api_key = None
    enabled = None
    access_all_groups = None
    deleted_at = None
    first_name = None
    last_name = None
    notifications = None
    created = None
    confirmation = None
    api_key_enabled = None
    license_type = None
    extra = None
    phone = None
    website = None
    company = None
    otp = None
    otp_required = None
    pwd_max_age = None
    pwd_expires = None
    max_session = None
    lockout = None

    def __str__(self):
        return "R_user[%s:%s]=%s" % (self.user_id, self.owner_id, self.email)

    def __repr__(self):
        return self.__str__()


mapper(UserRow, UsersTable)
